package edu.lyun.studenttest.controller;

import edu.lyun.studenttest.entity.Student;
import edu.lyun.studenttest.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller("/")
public class MainController {
    @Resource
    StudentService studentService;

    @ResponseBody
    @GetMapping(value = "/get-students", produces = "application/json;charset=UTF-8")
    public List<Student> getStudent() {
        return studentService.getStudents();
    }

    @ResponseBody
    @GetMapping(value = "/delete-student-by-id", produces = "application/json;charset=UTF-8")
    public int deleteStudentById(int id) {
        return studentService.deleteStudentById(id);
    }

    @ResponseBody
    @PostMapping(value = "/update-student", produces = "application/json;charset=UTF-8")
    public int updateStudent(@RequestBody Student student) {
        return studentService.updateStudent(student);
    }
    @ResponseBody
    @PostMapping(value = "/append-student", produces = "application/json;charset=UTF-8")
    public int appendStudent(@RequestBody Student student) {
        return studentService.appendStudent(student);
    }
    @GetMapping(value = "/")
    public String index() {
        return "index";
    }

}
